
const moment = require('moment');
module.exports = app => {
  const {STRING, DATE, BIGINT} = app.Sequelize;

  const Banner = app.model.define('banner', {
    id: {
      type: BIGINT,
      primaryKey: true,
      autoIncrement: true,
    },
    resource_id: BIGINT,
    href: STRING(100),
    name: STRING(50),
    create_time: {
      type: DATE,
      get() {
        return moment(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    modify_time: {
      type: DATE,
      get() {
        return moment(this.getDataValue('modify_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    img: STRING(200)
  }, {
    tableName: 'hy_banner',
    timestamps: false,
  });

  Banner.associate = function() {
    app.model.Banner.belongsTo(app.model.Resource, {
      as: 'source',
      foreignKey: 'resource_id',
      targetKey: 'id'
    });
  };


  return Banner;
};
